package com.yunpeng.dynamic.page.dao.model;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * BaseDO 基础字段表
 *
 * @author : Moore(hemw)
 * @date : 2020-03-26
 */
public abstract class BaseDO implements Serializable {

    /**
     * 自增记录id
     */
    protected Long id;
    /**
     * 数据标志位，默认为1
     * 1 正常使用
     * 0 逻辑删除
     */
    protected Short flag;
    /**
     * 创建人
     */
    protected String creator;
    /**
     * 创建时间
     */
    protected LocalDateTime createTime;
    /**
     * 更新人
     */
    protected String updater;
    /**
     * 更新时间
     */
    protected LocalDateTime updateTime;

    public BaseDO() {
        flag = 1;
    }

    public BaseDO(Long id, Short flag, String creator, LocalDateTime createTime, String updater, LocalDateTime updateTime) {
        this.id = id;
        this.flag = 1;
        this.creator = creator;
        this.createTime = createTime;
        this.updater = updater;
        this.updateTime = updateTime;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Short getFlag() {
        if (flag == null) {
            flag = 1;
        }
        return flag;
    }

    public void setFlag(Short flag) {
        this.flag = flag;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getUpdater() {
        return updater;
    }

    public void setUpdater(String updater) {
        this.updater = updater;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "BaseDO{" +
                "id=" + id +
                ", flag=" + flag +
                ", creator='" + creator + '\'' +
                ", createTime=" + createTime +
                ", updater='" + updater + '\'' +
                ", updateTime=" + updateTime +
                '}';
    }

    public void initForNew(String userCode) {
        this.flag = 1;
        this.creator = userCode;
        this.updater = userCode;
        LocalDateTime now = LocalDateTime.now();
        this.createTime = now;
        this.updateTime = now;
    }

}
